/* eslint-disable unused-imports/no-unused-vars */
import { useRouter } from 'vue-router'
import { useReport } from '@/composables/hooks/useReport'

export default defineNuxtPlugin((nuxtApp) => {
  const router = useRouter()
  router.beforeEach(async (to, from) => {
    // 保存跳转前的地址，第一次进入路由使用 referrer 作为来源地址，路由跳转时使用当前页面地址作为 referrer
    window.page_ref = window.page_ref ? location.href : document.referrer
  })
  router.afterEach(() => {
    useReport('pageview', {})
  })
})
